package cn.jbolt.wechat.admin.menu;

import cn.jbolt.core.api.JBoltApiBaseController;
import cn.jbolt.core.api.httpmethod.JBoltHttpGet;
import cn.jbolt.core.api.httpmethod.JBoltHttpPost;
import cn.jbolt.core.enumutil.JBoltEnum;
import cn.jbolt.core.permission.CheckPermission;
import cn.jbolt.core.permission.UnCheckIfSystemAdmin;
import cn.jbolt.wechat.common.WechatMenuType;
import cn.jbolt.wechat.model.WechatMenu;
import cn.jbolt.wechat.permission.WechatPermissionKey;
import cn.jbolt.wechat.service.JBoltWechatMenuService;
import cn.jbolt.wechat.service.JBoltWechatMpinfoService;
import com.jfinal.aop.Inject;
import com.jfinal.core.Path;
import com.jfinal.core.paragetter.Para;

/**   
 * 微信菜单管理
 * @ClassName:  WechatMenuAdminController   
 * @author: JFinal学院-小木 QQ：909854136 
 * @date:   2019年5月12日 下午11:37:20   
 */
@CheckPermission(WechatPermissionKey.WECHAT_MENU)
@UnCheckIfSystemAdmin
@Path("/api/admin/wechatMenu")
public class WechatMenuAdminController extends JBoltApiBaseController {
	@Inject
	private JBoltWechatMpinfoService wechatMpinfoService;
	@Inject
	private JBoltWechatMenuService service;




	/**
	 * 读取一级菜单数据
	 */
	@JBoltHttpGet
	public void level1List(){
		renderJBoltApiSuccessWithData(service.getLevel1Menus(getLong(0)));
	}
	/**
	 * 读取二级菜单数据
	 */
	@JBoltHttpGet
	public void level2List(){
		renderJBoltApiSuccessWithData(service.getLevel2Menus(getLong(0),getLong(1)));
	}
	/**
	 * 进入单个菜单的编辑界面
	 */
	public void index(){
		Long mpId=getLong(0);
		Long id=getLong(1);

		WechatMenu menu = service.findById(id);
		if(menu.getMpId().longValue() != mpId.longValue()){
			renderJBoltApiFail("参数异常");
			return;
		}

		renderJBoltApiSuccessWithData(menu);

	}

	
	/**
	 * 新增数据
	 */
	@JBoltHttpPost
	public void save(@Para("mpId") Long mpId, @Para("menu") WechatMenu menu){
		renderJBoltApiRet(service.save(mpId, menu));
	}
	/**
	 * 修改数据
	 */
	@JBoltHttpPost
	public void update(@Para("mpId") Long mpId, @Para("menu") WechatMenu menu){
		renderJBoltApiRet(service.update(mpId, menu));
	}
	
	/**
	 * 删除数据
	 * @return
	 */
	public void delete(){
		renderJBoltApiRet(service.delete(getLong(0),getLong(1)));
	}
	/**
	 * 发布到公众号
	 * @return
	 */
	public void publish(){
		renderJBoltApiRet(service.publish(getLong(0)));
	}
	
	/**
	 * 类型列表
	 */
	public void types() {
		renderJBoltApiSuccessWithData(JBoltEnum.getEnumOptionList(WechatMenuType.class));
	}
}
